﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

namespace Lib_general
{
    public class Function
    {
        private Exec_Database exec = new Exec_Database();

        public DataRow getrowbyid(DataTable dt, string exp)
        {
            try
            {
                DataRow[] r = dt.Select(exp);
                return r[0];
            }
            catch { return null; }
        }
        public int getRandom()
        {
            System.Threading.Thread.Sleep(10);
            Random r = new Random();
            return r.Next(999);
        }
        public decimal getidyymmddhhmiss_stt_computer
        {
            get
            {
                return decimal.Parse(getyymmddhhmiss() + getRandom().ToString().PadLeft(3, '0'));
            }
        }
        public string getyymmddhhmiss()
        {
            return exec.Get_data("select YEAR(GETDATE())").Tables[0].Rows[0][0].ToString().Substring(2,2) + exec.Get_data("select MONTH(GETDATE())").Tables[0].Rows[0][0].ToString().PadLeft(2, '0') + exec.Get_data("select DAY(GETDATE())").Tables[0].Rows[0][0].ToString().PadLeft(2, '0') + DateTime.Now.Hour.ToString().PadLeft(2, '0') + DateTime.Now.Minute.ToString().PadLeft(2, '0') + DateTime.Now.Second.ToString().PadLeft(2, '0');
        }
        public void LoadCombobox(System.Windows.Forms.ComboBox combo, string valuemember, string displaymember, DataTable datasource)
        {
            try
            {
                combo.DisplayMember = displaymember;
                combo.ValueMember = valuemember;
                combo.DataSource = datasource;
            }
            catch { }
        }
    }
}
